#include <func.h>

int main(int argc, char* argv[])
{
    pid_t pid = fork();
    switch(pid)
    {
    case -1:
        error(1, errno, "fork");
    case 0:
        printf("child: pid = %d, ppid = %d", getpid(), getppid());
        char buf[1024];
        getcwd(buf, 1024);
        puts(buf);
        if(chdir("/") == -1) //加一个命令行参数
            error(1, errno, "chdir");
        getcwd(buf, 1024);
        puts(buf);
        break;
    default:
        printf("parent: pid = %d, chile_pid = %d", getpid(), pid);
        sleep(5);
        char* parent_cwd = getcwd(NULL, 0);
        puts(parent_cwd);
        free(parent_cwd);
        break;
    }
    return 0;
}
